<?php
if( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jobprofile extends CI_Controller
{


	function __construct()
	{
		parent::__construct();
		// check if user logged in
		if(!$this->ion_auth->logged_in()){
			redirect('auth/login');
		}
		$this->load->library('form_validation');
		$this->load->model('user/jobprofile_model');
	}
	

	
	function get_efficiency_by_user_type_id()
	{
		$user_type_id = $_REQUEST['user_type'];
		//exit;
		$default_options  =  $this->jobprofile_model->get_efficiency_by_user_type_id($user_type_id);
		//print_r($default_options);
		
		$j=1;
		foreach($default_options as $default_option)
		{
			
			echo '<input type="text" name="efficiencyname[]" value="'.$default_option->name.'">';
			echo ' <input type="text" id="id'.$j++.'" name="efficiencylevel[]" placeholder="level in %">';
			echo "<br>";
		}
		
	}
	
	function get_skills_by_user_type_id()
	{
		$user_type_id = $_REQUEST['user_type'];
		//exit;
		$default_options  =  $this->jobprofile_model->get_skills_by_user_type_id($user_type_id);

		foreach($default_options as $default_option)
		{
			echo '<input type="hidden" name="skillid[]" value="'.$default_option->id.'" >';
			echo '<input type="text" name="skillname[]" value="'.$default_option->name.'">';
			echo ' <input type="text" name="skilllevel[]" placeholder="level in %" onkeyup="check(this)">';
			echo "<br>";
		}
	}
	function get_tools_by_user_type_id()
	{
		$user_type_id = $_REQUEST['user_type'];
		//exit;
		$default_options  =  $this->jobprofile_model->get_tools_by_user_type_id($user_type_id);
		//print_r($default_options);
		foreach($default_options as $default_option)
		{
			echo '<input type="text" name="toolname[]" value="'.$default_option->name.'">';
			echo ' <input type="text" name="toollevel[]" placeholder="level in %" onkeyup="check(this)">';
			echo "<br>";
		}
	}
			
		
	function viewprofile($id=null)
	{
		//$data['userid'] = $id;
		if(isset($id))
		{
			$user= $id;
		}else
		{
			$user=$this->session->userdata('user_id');		
		}
		$data['userid'] = $user;
					
		//echo $id;
		//exit;
		//$users = $_REQUEST['user'];
		$data['getefficiencyid'] = $this->jobprofile_model->efficiency_getall_by_id($user);
		$data['efficiencychart'] = $this->jobprofile_model->efficiencychart($user);
		$data['efficiencyfields'] = $this->jobprofile_model->efficiencyfields($user);
		$data['skillschart'] = $this->jobprofile_model->skillschart($user);
		$data['toolschart'] = $this->jobprofile_model->toolschart($user);
		$data['hobbies'] = $this->jobprofile_model->hobbies_getall_by_id($user);
		$data['hobbyimage'] = $this->jobprofile_model->hobbyimage($user);
		$data['coffeebyid'] = $this->jobprofile_model->coffeebyid($user);
		$data['userdetails'] = $this->jobprofile_model->userdetails($user);
		$data['designationbyid'] = $this->jobprofile_model->designationbyid($user);
		$data['skillsimage'] = $this->jobprofile_model->skillsimage($user);
		$data['getskillsid'] = $this->jobprofile_model->skills_getall_by_id($user);
		$data['gettoolsid'] = $this->jobprofile_model->tools_getall_by_id($user);
		$data['user'] = $this->jobprofile_model->get_user_details($this->session->userdata('user_id'));
		$data['jobs'] = $this->jobprofile_model->get_job_details();
		//$data['query'] = $this->jobprofile_model->tools_getall();
		//$data['query'] = $this->jobprofile_model->hobbies_getall();

		$meta['page_title'] = "View Job Profile";
		$this->load->view('common/header',$meta);
		$this->load->view('user/view-jobprofile',$data);
		$this->load->view('common/footer');
		//echo $id;

	}
	function do_upload()
	{
		$config['upload_path'] = './assets/uploads/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '1000';
		$config['max_width']  = '1024';
		$config['max_height']  = '768';
//exit;
		$this->load->library('upload', $config);

		if ( ! $this->upload->do_upload())
		{
			$error = array('error' => $this->upload->display_errors());
			//print_r($error);
			
			redirect('user/wall','refresh');
			//$this->load->view('upload_form', $error);
		}
		else
		{
			$data['upload_data' ] = ($this->upload->data());
			
			 
			$this->jobprofile_model->do_upload($this->session->userdata('user_id'),$data['upload_data' ]['file_name']);
			
			$this->session->set_userdata('profile_image', $data['upload_data' ]['file_name']);
					
			redirect('user/wall','refresh',$data);
		}
	}
	

	}